//click_list_units.sqf
#include "ACV_Constantes.h"
#include "ACV_ID_main_dlg.h"
private ["_arr","_control","_index","_display","_map","_btn_delete","_list_wp",
"_legend_wp","_add_wp","_edit_wp","_del_wp","_old_group","_varname",
"_grp","_pos","_oldpos","_arr_wp","_wp","_x","_no","_strtype","_idx","_wp_pos"];
disableSerialization;
_arr = _this select 0;
_control = _arr select 0;
_index   = _arr select 1;
_display = findDisplay ACV_DLG_ID_Main_Dlg;
_map =  _display displayCtrl ACV_DLG_ID_Main_Map;
_btn_delete = _display displayCtrl ACV_DLG_ID_Main_BtnDeleteUnit;
_list_wp =  _display displayCtrl ACV_DLG_ID_Main_ListWp;
_legend_wp = _display displayCtrl ACV_DLG_ID_Main_LegendWp;
_add_wp = _display displayCtrl ACV_DLG_ID_Main_AddWp;
_edit_wp = _display displayCtrl ACV_DLG_ID_Main_EditWp;
_del_wp = _display displayCtrl ACV_DLG_ID_Main_DelWp;
_old_group = group player;
if (_index > -1) then {
	call ACV_FNCT_ClearAll_WpMarkers;
	_varname = _control lbData _index;
	if (isnil "_varname") then {diag_log "ACV Is Nil";}
	else { if (_varname == "") then {diag_log "ACV Empty";}; };
	call compile format ["_grp = %1",_varname];
	_grp = "";
	call compile format["_grp = %1;",_varname];
	_pos = getpos (leader _grp);
	_oldpos = getMarkerPos ACV_MARKER_LOC_Unit;
	if (isnil("ACV_MARKER_LOC_Unit")) then {
		ACV_MARKER_LOC_Unit = createMarkerLocal [_varname,_pos] ;
	};
	ACV_MARKER_LOC_Unit setMarkerShapeLocal "ICON";
	ACV_MARKER_LOC_Unit setMarkerTypeLocal "DOT";
	ACV_MARKER_LOC_Unit setMarkerPosLocal _pos;
	ACV_MARKER_LOC_Unit setMarkerSizeLocal [0.5,0.5];
	ACV_MARKER_LOC_Unit setMarkerTextLocal (_varname);
	ACV_MARKER_LOC_Unit setMarkerColorLocal ([_grp] call R3F_FNCT_GetMarkerColor);
	ACV_MARKER_LOC_Unit setMarkerAlphaLocal 0.5;
	if (ACV_Move_Map_Auto) then {
		if ((_pos distance [0,0,0]) > 10) then {
			if (((_oldpos distance _pos) > 500) && (!ACV_Filling_Dlg)) then {
				_map ctrlmapanimadd [0.5,1,_pos];
		   		_map ctrlmapanimadd [0.5,0.06,_pos];
		   		ctrlmapanimcommit _map;
			};
		};
	};
	lbclear _list_wp;
	_arr_wp = waypoints _grp;
	{	_wp = _x;
		_no = _wp select 1;
		_strtype = waypointType _wp;
		_strtype = [_strtype] call ACV_FNCT_GetFrenchMarker;
		_idx = _list_wp lbAdd format["#%1 %2",_no,_strtype];
		_list_wp lbSetValue [_idx,_no];
		_wp_pos = getWPPos _wp;
		_wp showWaypoint "ALWAYS";
	} foreach _arr_wp;
	_list_wp lbSetCurSel 0;
};
_btn_delete ctrlEnable (_index > -1);
//_list_wp lbsetcursel -1;
_list_wp ctrlEnable ((count _arr_wp) > 0);
_add_wp ctrlEnable ((count _arr_wp) > 0);
_edit_wp ctrlEnable ((count _arr_wp) > 0);
_del_wp ctrlEnable ((count _arr_wp) > 1);